#ifndef DESKTOP_ELEMENT_H
#define DESKTOP_ELEMENT_H

#include "js-engine.h"

#include <glib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>

typedef struct _desktop_element desktop_element;

struct _desktop_element {
    gchar *type;
    gchar *name;
    GHashTable *attrs;

    desktop_element *parent;
    GList *children;
    GList *text;

    GtkWidget *view;
    JSObject *jsobj;
    js_engine *engine;
	
    void *private;
};

enum ElementID {
    ELEMENT_UNKNOWN,
    ELEMENT_VIEW,
    ELEMENT_BUTTON,
    ELEMENT_CHECKBOX,
    ELEMENT_OBJECT,
    ELEMENT_CONTENTAREA,
    ELEMENT_DIV,
    ELEMENT_EDIT,
    ELEMENT_IMG,
    ELEMENT_LABEL,
    ELEMENT_A,
    ELEMENT_PROGRESSBAR,
    ELEMENT_RADIO,
    ELEMENT_LISTBOX,
    ELEMENT_LISTITEM,
    ELEMENT_SCRIPT,
    /* unused elements */
    ELEMENT_BASICELEMENT,
    ELEMENT_ELEMENTS
};

struct Element
{
    gchar *element_name;
    enum ElementID id;
    void (*function) (js_engine *engine, desktop_element *widget);
};

#define NAME_SCRIPT "script"
#define NAME_VIEW "view"
#define NAME_BASICELEMENT "basicElement"
#define NAME_ELEMENTS "elements"
#define NAME_BUTTON "button"
#define NAME_CHECKBOX "checkbox"
#define NAME_OBJECT "object"
#define NAME_CONTENTAREA "contentArea"
#define NAME_DIV "div"
#define NAME_EDIT "edit"
#define NAME_IMG "img"
#define NAME_LABEL "label"
#define NAME_A "a"
#define NAME_PROGRESSBAR "progressBar"
#define NAME_LISTBOX "listbox"
#define NAME_LISTITEM "item"
#define NAME_OPTIONS "options"
#define NAME_MENU "menu"
#define NAME_RADIO "radio"

#define DEFAULT_FONT_SIZE 9
desktop_element *desktop_element_new_with_name(const gchar *type,
					     const gchar *name, js_engine *engine);
desktop_element *desktop_element_new(const gchar *type, js_engine *engine);
void desktop_element_destroy(desktop_element *widget);

void desktop_element_set_name(desktop_element *widget, const gchar *name);
void desktop_element_set_attr(desktop_element *widget, const gchar *key,
			     const gchar *value);
void desktop_element_add_child(desktop_element *parent, desktop_element *child);
void desktop_element_set_text(desktop_element *widget, const gchar *text);
gchar* desktop_element_get_text(desktop_element *widget);

void desktop_element_dump(desktop_element *widget, int indent);

JSBool desktop_element_call_handler(desktop_element *widget, const gchar *handler_name);
gboolean desktop_element_set_view(js_engine *engine, desktop_element *widget);
void desktop_element_set_position(desktop_element *root, GList *elements);

void desktop_element_set_view_fixed(js_engine *engine, desktop_element *widget);
void desktop_element_set_view_button(js_engine *engine, desktop_element *widget);
void desktop_element_set_view_checkbox(js_engine *engine, desktop_element *widget);
void desktop_element_set_view_edit(js_engine *engine, desktop_element *widget);
void desktop_element_set_view_img(js_engine *engine, desktop_element *widget);
void desktop_element_set_view_label(js_engine *engine, desktop_element *widget);
void desktop_element_set_view_a(js_engine *engine, desktop_element *widget);
void desktop_element_set_view_progressbar(js_engine *engine, desktop_element *widget);
void desktop_element_set_view_radio(js_engine *engine, desktop_element *widget);
void desktop_element_set_view_listbox(js_engine *engine, desktop_element *widget);
void desktop_element_set_view_listitem(js_engine *engine, desktop_element *widget);
void desktop_element_set_view_div(js_engine *engine, desktop_element *widget);

void *desktop_element_get_private(desktop_element *widget);
void desktop_element_set_private(desktop_element *widget, gpointer *ptr);
gchar *trans_unix_path_new(const gchar *original);

#endif
